<!DOCTYPE html>
<html lang="en-us" dir="ltr">
    <head><meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'><meta name='description' content='crm项目: 权限系统(做成公共组件app) 只要有不同角色的人员来使用系统，那么就肯定需要权限系统。
web程序是通过 url 的切换来查看不同的页面（功能），所以权限指的其实就是URL，对url控制就是对权限的控制。
权限表结构设计 一个用户可以有多个权限。 一个权限可以分配给多个用户。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 from django.db import models class Permission(models.Model): &amp;#34;&amp;#34;&amp;#34; 权限表 &amp;#34;&amp;#34;&amp;#34; title = models.CharField(verbose_name=&amp;#39;标题&amp;#39;, max_length=32) url = models.CharField(verbose_name=&amp;#39;含正则的URL&amp;#39;, max_length=128) def __str__(self): return self.title class Role(models.Model): &amp;#34;&amp;#34;&amp;#34; 角色 &amp;#34;&amp;#34;&amp;#34; title = models.'><title>django</title>

<link rel='canonical' href='http://meruro.cn/p/django/'>

<link rel="stylesheet" href="/scss/style.min.5a8e892f6fa14515e9065eee1f5d2e05302606ec7f11750b2fb95198f9cdcbfd.css"><meta property='og:title' content='django'>
<meta property='og:description' content='crm项目: 权限系统(做成公共组件app) 只要有不同角色的人员来使用系统，那么就肯定需要权限系统。
web程序是通过 url 的切换来查看不同的页面（功能），所以权限指的其实就是URL，对url控制就是对权限的控制。
权限表结构设计 一个用户可以有多个权限。 一个权限可以分配给多个用户。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 from django.db import models class Permission(models.Model): &amp;#34;&amp;#34;&amp;#34; 权限表 &amp;#34;&amp;#34;&amp;#34; title = models.CharField(verbose_name=&amp;#39;标题&amp;#39;, max_length=32) url = models.CharField(verbose_name=&amp;#39;含正则的URL&amp;#39;, max_length=128) def __str__(self): return self.title class Role(models.Model): &amp;#34;&amp;#34;&amp;#34; 角色 &amp;#34;&amp;#34;&amp;#34; title = models.'>
<meta property='og:url' content='http://meruro.cn/p/django/'>
<meta property='og:site_name' content='梅鲁梅鲁梅鲁梅~'>
<meta property='og:type' content='article'><meta property='article:section' content='Post' /><meta property='article:tag' content='代码' /><meta property='article:published_time' content='2019-06-18T22:00:07&#43;00:00'/><meta property='article:modified_time' content='2019-06-18T22:00:07&#43;00:00'/>
<meta name="twitter:title" content="django">
<meta name="twitter:description" content="crm项目: 权限系统(做成公共组件app) 只要有不同角色的人员来使用系统，那么就肯定需要权限系统。
web程序是通过 url 的切换来查看不同的页面（功能），所以权限指的其实就是URL，对url控制就是对权限的控制。
权限表结构设计 一个用户可以有多个权限。 一个权限可以分配给多个用户。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 from django.db import models class Permission(models.Model): &amp;#34;&amp;#34;&amp;#34; 权限表 &amp;#34;&amp;#34;&amp;#34; title = models.CharField(verbose_name=&amp;#39;标题&amp;#39;, max_length=32) url = models.CharField(verbose_name=&amp;#39;含正则的URL&amp;#39;, max_length=128) def __str__(self): return self.title class Role(models.Model): &amp;#34;&amp;#34;&amp;#34; 角色 &amp;#34;&amp;#34;&amp;#34; title = models.">
    </head>
    <body class="
    article-page
    ">
    <script>
        (function() {
            const colorSchemeKey = 'StackColorScheme';
            if(!localStorage.getItem(colorSchemeKey)){
                localStorage.setItem(colorSchemeKey, "auto");
            }
        })();
    </script><script>
    (function() {
        const colorSchemeKey = 'StackColorScheme';
        const colorSchemeItem = localStorage.getItem(colorSchemeKey);
        const supportDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches === true;

        if (colorSchemeItem == 'dark' || colorSchemeItem === 'auto' && supportDarkMode) {
            

            document.documentElement.dataset.scheme = 'dark';
        } else {
            document.documentElement.dataset.scheme = 'light';
        }
    })();
</script>
<div class="container main-container flex on-phone--column extended"><aside class="sidebar left-sidebar sticky ">
    <button class="hamburger hamburger--spin" type="button" id="toggle-menu" aria-label="Toggle Menu">
        <span class="hamburger-box">
            <span class="hamburger-inner"></span>
        </span>
    </button>

    <header>
        
            
            <figure class="site-avatar">
                <a href="/">
                
                    
                    
                    
                        
                        <img src="/img/ava_hu31add2dceb44736f969f74989490346b_19511_300x0_resize_q75_box.jpg" width="300"
                            height="300" class="site-logo" loading="lazy" alt="Avatar">
                    
                
                </a>
                
                    <span class="emoji">🍥</span>
                
            </figure>
            
        
        
        <div class="site-meta">
            <h1 class="site-name"><a href="/">梅鲁梅鲁梅鲁梅~</a></h1>
            <h2 class="site-description">朝闻道,夕死可矣.</h2>
        </div>
    </header><ol class="social-menu">
            
                <li>
                    <a 
                        href='https://github.com/CaiJimmy/hugo-theme-stack'
                        target="_blank"
                        title="GitHub"
                    >
                        
                        
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-github" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" />
</svg>



                        
                    </a>
                </li>
            
                <li>
                    <a 
                        href='https://twitter.com'
                        target="_blank"
                        title="Twitter"
                    >
                        
                        
                            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-twitter" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z" />
</svg>



                        
                    </a>
                </li>
            
        </ol><ol class="menu" id="main-menu">
        
        
        

        <li >
            <a href='/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-home" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <polyline points="5 12 3 12 12 3 21 12 19 12" />
  <path d="M5 12v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-7" />
  <path d="M9 21v-6a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v6" />
</svg>



                
                <span>Home</span>
            </a>
        </li>
        
        

        <li >
            <a href='/about/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-user" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="7" r="4" />
  <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2" />
</svg>



                
                <span>About</span>
            </a>
        </li>
        
        

        <li >
            <a href='/archives/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-archive" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <rect x="3" y="4" width="18" height="4" rx="2" />
  <path d="M5 8v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-10" />
  <line x1="10" y1="12" x2="14" y2="12" />
</svg>



                
                <span>Archives</span>
            </a>
        </li>
        
        

        <li >
            <a href='/search/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-search" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="10" cy="10" r="7" />
  <line x1="21" y1="21" x2="15" y2="15" />
</svg>



                
                <span>Search</span>
            </a>
        </li>
        
        

        <li >
            <a href='/links/' >
                
                
                
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" />
  <path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" />
</svg>



                
                <span>Links</span>
            </a>
        </li>
        

        <div class="menu-bottom-section">
                <li id="i18n-switch">  
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-language" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
  <path d="M4 5h7" />
  <path d="M9 3v2c0 4.418 -2.239 8 -5 8" />
  <path d="M5 9c-.003 2.144 2.952 3.908 6.7 4" />
  <path d="M12 20l4 -9l4 9" />
  <path d="M19.1 18h-6.2" />
</svg>



                    <select name="language" onchange="window.location.href = this.selectedOptions[0].value">
                        
                            <option value="http://meruro.cn/" selected>English</option>
                        
                            <option value="http://meruro.cn/zh-cn/" >中文</option>
                        
                            <option value="http://meruro.cn/ar/" >عربي</option>
                        
                    </select>
                </li>
            
            
            
                <li id="dark-mode-toggle">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-left" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="8" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-toggle-right" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="16" cy="12" r="2" />
  <rect x="2" y="6" width="20" height="12" rx="6" />
</svg>



                    <span>Dark Mode</span>
                </li>
            
        </div>
    </ol>
</aside>
<main class="main full-width">
    <article class="main-article">
    <header class="article-header">

    <div class="article-details">
    

    <div class="article-title-wrapper">
        <h2 class="article-title">
            <a href="/p/django/">django</a>
        </h2>
    
        
    </div>

    
    <footer class="article-time">
        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-calendar-time" width="56" height="56" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
  <circle cx="18" cy="18" r="4" />
  <path d="M15 3v4" />
  <path d="M7 3v4" />
  <path d="M3 11h16" />
  <path d="M18 16.496v1.504l1 1" />
</svg>
                <time class="article-time--published">Jun 18, 2019</time>
            </div>
        

        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clock" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <polyline points="12 7 12 12 15 15" />
</svg>



                <time class="article-time--reading">
                    4 minute read
                </time>
            </div>
        
    </footer>
    

    
</div>
</header>

    <section class="article-content">
    
    
    <h1 id="crm项目">crm项目:</h1>
<h2 id="权限系统做成公共组件app">权限系统(做成公共组件app)</h2>
<p>只要有不同角色的人员来使用系统，那么就肯定需要权限系统。</p>
<p>web程序是通过 url 的切换来查看不同的页面（功能），所以权限指的其实就是URL，对url控制就是对权限的控制。</p>
<h3 id="权限表结构设计">权限表结构设计</h3>
<ul>
<li>一个用户可以有多个权限。</li>
<li>一个权限可以分配给多个用户。</li>
</ul>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Permission</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;
</span></span></span><span class="line"><span class="cl"><span class="s2">    权限表
</span></span></span><span class="line"><span class="cl"><span class="s2">    &#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;标题&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">url</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;含正则的URL&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">128</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">title</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">Role</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;
</span></span></span><span class="line"><span class="cl"><span class="s2">    角色
</span></span></span><span class="line"><span class="cl"><span class="s2">    &#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;角色名称&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">permissions</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ManyToManyField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;拥有的所有权限&#39;</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="s1">&#39;Permission&#39;</span><span class="p">,</span> <span class="n">blank</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">title</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="k">class</span> <span class="nc">UserInfo</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">    <span class="s2">&#34;&#34;&#34;
</span></span></span><span class="line"><span class="cl"><span class="s2">    用户表
</span></span></span><span class="line"><span class="cl"><span class="s2">    &#34;&#34;&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;用户名&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">password</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;密码&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">64</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">email</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;邮箱&#39;</span><span class="p">,</span> <span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">roles</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ManyToManyField</span><span class="p">(</span><span class="n">verbose_name</span><span class="o">=</span><span class="s1">&#39;拥有的所有角色&#39;</span><span class="p">,</span> <span class="n">to</span><span class="o">=</span><span class="s1">&#39;Role&#39;</span><span class="p">,</span> <span class="n">blank</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="k">def</span> <span class="fm">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">models</span><span class="o">.</span><span class="n">py</span> <span class="n">示例</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="django中的model字段">django中的model字段</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt">  1
</span><span class="lnt">  2
</span><span class="lnt">  3
</span><span class="lnt">  4
</span><span class="lnt">  5
</span><span class="lnt">  6
</span><span class="lnt">  7
</span><span class="lnt">  8
</span><span class="lnt">  9
</span><span class="lnt"> 10
</span><span class="lnt"> 11
</span><span class="lnt"> 12
</span><span class="lnt"> 13
</span><span class="lnt"> 14
</span><span class="lnt"> 15
</span><span class="lnt"> 16
</span><span class="lnt"> 17
</span><span class="lnt"> 18
</span><span class="lnt"> 19
</span><span class="lnt"> 20
</span><span class="lnt"> 21
</span><span class="lnt"> 22
</span><span class="lnt"> 23
</span><span class="lnt"> 24
</span><span class="lnt"> 25
</span><span class="lnt"> 26
</span><span class="lnt"> 27
</span><span class="lnt"> 28
</span><span class="lnt"> 29
</span><span class="lnt"> 30
</span><span class="lnt"> 31
</span><span class="lnt"> 32
</span><span class="lnt"> 33
</span><span class="lnt"> 34
</span><span class="lnt"> 35
</span><span class="lnt"> 36
</span><span class="lnt"> 37
</span><span class="lnt"> 38
</span><span class="lnt"> 39
</span><span class="lnt"> 40
</span><span class="lnt"> 41
</span><span class="lnt"> 42
</span><span class="lnt"> 43
</span><span class="lnt"> 44
</span><span class="lnt"> 45
</span><span class="lnt"> 46
</span><span class="lnt"> 47
</span><span class="lnt"> 48
</span><span class="lnt"> 49
</span><span class="lnt"> 50
</span><span class="lnt"> 51
</span><span class="lnt"> 52
</span><span class="lnt"> 53
</span><span class="lnt"> 54
</span><span class="lnt"> 55
</span><span class="lnt"> 56
</span><span class="lnt"> 57
</span><span class="lnt"> 58
</span><span class="lnt"> 59
</span><span class="lnt"> 60
</span><span class="lnt"> 61
</span><span class="lnt"> 62
</span><span class="lnt"> 63
</span><span class="lnt"> 64
</span><span class="lnt"> 65
</span><span class="lnt"> 66
</span><span class="lnt"> 67
</span><span class="lnt"> 68
</span><span class="lnt"> 69
</span><span class="lnt"> 70
</span><span class="lnt"> 71
</span><span class="lnt"> 72
</span><span class="lnt"> 73
</span><span class="lnt"> 74
</span><span class="lnt"> 75
</span><span class="lnt"> 76
</span><span class="lnt"> 77
</span><span class="lnt"> 78
</span><span class="lnt"> 79
</span><span class="lnt"> 80
</span><span class="lnt"> 81
</span><span class="lnt"> 82
</span><span class="lnt"> 83
</span><span class="lnt"> 84
</span><span class="lnt"> 85
</span><span class="lnt"> 86
</span><span class="lnt"> 87
</span><span class="lnt"> 88
</span><span class="lnt"> 89
</span><span class="lnt"> 90
</span><span class="lnt"> 91
</span><span class="lnt"> 92
</span><span class="lnt"> 93
</span><span class="lnt"> 94
</span><span class="lnt"> 95
</span><span class="lnt"> 96
</span><span class="lnt"> 97
</span><span class="lnt"> 98
</span><span class="lnt"> 99
</span><span class="lnt">100
</span><span class="lnt">101
</span><span class="lnt">102
</span><span class="lnt">103
</span><span class="lnt">104
</span><span class="lnt">105
</span><span class="lnt">106
</span><span class="lnt">107
</span><span class="lnt">108
</span><span class="lnt">109
</span><span class="lnt">110
</span><span class="lnt">111
</span><span class="lnt">112
</span><span class="lnt">113
</span><span class="lnt">114
</span><span class="lnt">115
</span><span class="lnt">116
</span><span class="lnt">117
</span><span class="lnt">118
</span><span class="lnt">119
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="n">AutoField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">int自增列</span><span class="err">，</span><span class="n">必须填入参数</span> <span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">BigAutoField</span><span class="p">(</span><span class="n">AutoField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">bigint自增列</span><span class="err">，</span><span class="n">必须填入参数</span> <span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="n">注</span><span class="err">：</span><span class="n">当model中如果没有自增列</span><span class="err">，</span><span class="n">则自动会创建一个列名为id的列</span>
</span></span><span class="line"><span class="cl">        
</span></span><span class="line"><span class="cl">        <span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="k">class</span> <span class="nc">UserInfo</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="c1"># 自动创建一个列名为id的且为自增的整数列</span>
</span></span><span class="line"><span class="cl">            <span class="n">username</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="k">class</span> <span class="nc">Group</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="c1"># 自定义自增列</span>
</span></span><span class="line"><span class="cl">            <span class="n">nid</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">AutoField</span><span class="p">(</span><span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">            <span class="n">SmallIntegerField</span><span class="p">(</span><span class="n">IntegerField</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">小整数</span> <span class="o">-</span><span class="mi">32768</span> <span class="err">～</span> <span class="mi">32767</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">PositiveSmallIntegerField</span><span class="p">(</span><span class="n">PositiveIntegerRelDbTypeMixin</span><span class="p">,</span> <span class="n">IntegerField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">正小整数</span> <span class="mi">0</span> <span class="err">～</span> <span class="mi">32767</span>
</span></span><span class="line"><span class="cl">    <span class="n">IntegerField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">整数列</span><span class="p">(</span><span class="n">有符号的</span><span class="p">)</span> <span class="o">-</span><span class="mi">2147483648</span> <span class="err">～</span> <span class="mi">2147483647</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">PositiveIntegerField</span><span class="p">(</span><span class="n">PositiveIntegerRelDbTypeMixin</span><span class="p">,</span> <span class="n">IntegerField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">正整数</span> <span class="mi">0</span> <span class="err">～</span> <span class="mi">2147483647</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">BigIntegerField</span><span class="p">(</span><span class="n">IntegerField</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">长整型</span><span class="p">(</span><span class="n">有符号的</span><span class="p">)</span> <span class="o">-</span><span class="mi">9223372036854775808</span> <span class="err">～</span> <span class="mi">9223372036854775807</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">BooleanField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">布尔值类型</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">NullBooleanField</span><span class="p">(</span><span class="n">Field</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">可以为空的布尔值</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">CharField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符类型</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">必须提供max_length参数</span><span class="err">，</span> <span class="n">max_length表示字符长度</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">TextField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">文本类型</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">EmailField</span><span class="p">(</span><span class="n">CharField</span><span class="p">)</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供验证机制</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">IPAddressField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供验证</span> <span class="n">IPV4</span> <span class="n">机制</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">GenericIPAddressField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供验证</span> <span class="n">Ipv4和Ipv6</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">参数</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">            <span class="n">protocol</span><span class="err">，</span><span class="n">用于指定Ipv4或Ipv6</span><span class="err">，</span> <span class="s1">&#39;both&#39;</span><span class="p">,</span><span class="s2">&#34;ipv4&#34;</span><span class="p">,</span><span class="s2">&#34;ipv6&#34;</span>
</span></span><span class="line"><span class="cl">            <span class="n">unpack_ipv4</span><span class="err">，</span> <span class="n">如果指定为True</span><span class="err">，</span><span class="n">则输入</span><span class="p">::</span><span class="n">ffff</span><span class="p">:</span><span class="mf">192.0.2.1</span><span class="n">时候</span><span class="err">，</span><span class="n">可解析为192</span><span class="mf">.0.2.1</span><span class="err">，</span><span class="n">开启刺功能</span><span class="err">，</span><span class="n">需要protocol</span><span class="o">=</span><span class="s2">&#34;both&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">URLField</span><span class="p">(</span><span class="n">CharField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供验证</span> <span class="n">URL</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">SlugField</span><span class="p">(</span><span class="n">CharField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供验证支持</span> <span class="n">字母</span><span class="err">、</span><span class="n">数字</span><span class="err">、</span><span class="n">下划线</span><span class="err">、</span><span class="n">连接符</span><span class="err">（</span><span class="n">减号</span><span class="err">）</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">CommaSeparatedIntegerField</span><span class="p">(</span><span class="n">CharField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">格式必须为逗号分割的数字</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">UUIDField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串类型</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供对UUID格式的验证</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">FilePathField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串</span><span class="err">，</span><span class="n">Django</span> <span class="n">Admin以及ModelForm中提供读取文件夹下文件的功能</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">参数</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">                <span class="n">path</span><span class="p">,</span>                      <span class="n">文件夹路径</span>
</span></span><span class="line"><span class="cl">                <span class="n">match</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>                <span class="n">正则匹配</span>
</span></span><span class="line"><span class="cl">                <span class="n">recursive</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>           <span class="n">递归下面的文件夹</span>
</span></span><span class="line"><span class="cl">                <span class="n">allow_files</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>          <span class="n">允许文件</span>
</span></span><span class="line"><span class="cl">                <span class="n">allow_folders</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>       <span class="n">允许文件夹</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">FileField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串</span><span class="err">，</span><span class="n">路径保存在数据库</span><span class="err">，</span><span class="n">文件上传到指定目录</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">参数</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">            <span class="n">upload_to</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span>      <span class="n">上传文件的保存路径</span>
</span></span><span class="line"><span class="cl">            <span class="n">storage</span> <span class="o">=</span> <span class="kc">None</span>      <span class="n">存储组件</span><span class="err">，</span><span class="n">默认django</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">files</span><span class="o">.</span><span class="n">storage</span><span class="o">.</span><span class="n">FileSystemStorage</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">ImageField</span><span class="p">(</span><span class="n">FileField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">字符串</span><span class="err">，</span><span class="n">路径保存在数据库</span><span class="err">，</span><span class="n">文件上传到指定目录</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">参数</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">            <span class="n">upload_to</span> <span class="o">=</span> <span class="s2">&#34;&#34;</span>      <span class="n">上传文件的保存路径</span>
</span></span><span class="line"><span class="cl">            <span class="n">storage</span> <span class="o">=</span> <span class="kc">None</span>      <span class="n">存储组件</span><span class="err">，</span><span class="n">默认django</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">files</span><span class="o">.</span><span class="n">storage</span><span class="o">.</span><span class="n">FileSystemStorage</span>
</span></span><span class="line"><span class="cl">            <span class="n">width_field</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>   <span class="n">上传图片的高度保存的数据库字段名</span><span class="err">（</span><span class="n">字符串</span><span class="err">）</span>
</span></span><span class="line"><span class="cl">            <span class="n">height_field</span><span class="o">=</span><span class="kc">None</span>   <span class="n">上传图片的宽度保存的数据库字段名</span><span class="err">（</span><span class="n">字符串</span><span class="err">）</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">DateTimeField</span><span class="p">(</span><span class="n">DateField</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">日期</span><span class="o">+</span><span class="n">时间格式</span> <span class="n">YYYY</span><span class="o">-</span><span class="n">MM</span><span class="o">-</span><span class="n">DD</span> <span class="n">HH</span><span class="p">:</span><span class="n">MM</span><span class="p">[:</span><span class="n">ss</span><span class="p">[</span><span class="o">.</span><span class="n">uuuuuu</span><span class="p">]][</span><span class="n">TZ</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">DateField</span><span class="p">(</span><span class="n">DateTimeCheckMixin</span><span class="p">,</span> <span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">日期格式</span>      <span class="n">YYYY</span><span class="o">-</span><span class="n">MM</span><span class="o">-</span><span class="n">DD</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">TimeField</span><span class="p">(</span><span class="n">DateTimeCheckMixin</span><span class="p">,</span> <span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">时间格式</span>      <span class="n">HH</span><span class="p">:</span><span class="n">MM</span><span class="p">[:</span><span class="n">ss</span><span class="p">[</span><span class="o">.</span><span class="n">uuuuuu</span><span class="p">]]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">DurationField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">长整数</span><span class="err">，</span><span class="n">时间间隔</span><span class="err">，</span><span class="n">数据库中按照bigint存储</span><span class="err">，</span><span class="n">ORM中获取的值为datetime</span><span class="o">.</span><span class="n">timedelta类型</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">FloatField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">浮点型</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">DecimalField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="mi">10</span><span class="n">进制小数</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">参数</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">            <span class="n">max_digits</span><span class="err">，</span><span class="n">小数总长度</span>
</span></span><span class="line"><span class="cl">            <span class="n">decimal_places</span><span class="err">，</span><span class="n">小数位长度</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">BinaryField</span><span class="p">(</span><span class="n">Field</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">        <span class="o">-</span> <span class="n">二进制类型</span>
</span></span><span class="line"><span class="cl">    <span class="c1">#自定义的字段</span>
</span></span><span class="line"><span class="cl">    <span class="k">class</span> <span class="nc">UnsignedIntegerField</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">        <span class="k">def</span> <span class="nf">db_type</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">connection</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="k">return</span> <span class="s1">&#39;integer UNSIGNED&#39;</span>
</span></span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="mf">1.</span><span class="n">触发Model中的验证和错误提示有两种方式</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">        <span class="n">a</span><span class="o">.</span> <span class="n">Django</span> <span class="n">Admin中的错误信息会优先根据Admiin内部的ModelForm错误信息提示</span><span class="err">，</span><span class="n">如果都成功</span><span class="err">，</span><span class="n">才来检查Model的字段并显示指定错误信息</span>
</span></span><span class="line"><span class="cl">        <span class="n">b</span><span class="o">.</span> <span class="n">使用ModelForm</span>
</span></span><span class="line"><span class="cl">        <span class="n">c</span><span class="o">.</span> <span class="n">调用Model对象的</span> <span class="n">clean_fields</span> <span class="n">方法</span><span class="err">，</span><span class="n">如</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># models.py</span>
</span></span><span class="line"><span class="cl">            <span class="k">class</span> <span class="nc">UserInfo</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">                <span class="n">nid</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">AutoField</span><span class="p">(</span><span class="n">primary_key</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">                <span class="n">username</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">                <span class="n">email</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">EmailField</span><span class="p">(</span><span class="n">error_messages</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;invalid&#39;</span><span class="p">:</span> <span class="s1">&#39;格式错了.&#39;</span><span class="p">})</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># Admin中修改错误提示</span>
</span></span><span class="line"><span class="cl">    <span class="c1"># admin.py</span>
</span></span><span class="line"><span class="cl">        <span class="kn">from</span> <span class="nn">django.contrib</span> <span class="kn">import</span> <span class="n">admin</span>
</span></span><span class="line"><span class="cl">        <span class="kn">from</span> <span class="nn">model_club</span> <span class="kn">import</span> <span class="n">models</span>
</span></span><span class="line"><span class="cl">        <span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">forms</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="k">class</span> <span class="nc">UserInfoForm</span><span class="p">(</span><span class="n">forms</span><span class="o">.</span><span class="n">ModelForm</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="n">age</span> <span class="o">=</span> <span class="n">forms</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">(</span><span class="n">initial</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">error_messages</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;required&#39;</span><span class="p">:</span> <span class="s1">&#39;请输入数值.&#39;</span><span class="p">,</span> <span class="s1">&#39;invalid&#39;</span><span class="p">:</span> <span class="s1">&#39;年龄必须为数值.&#39;</span><span class="p">})</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">            <span class="k">class</span> <span class="nc">Meta</span><span class="p">:</span>
</span></span><span class="line"><span class="cl">                <span class="n">model</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">UserInfo</span>
</span></span><span class="line"><span class="cl">                <span class="c1"># fields = (&#39;username&#39;,)</span>
</span></span><span class="line"><span class="cl">                <span class="n">fields</span> <span class="o">=</span> <span class="s2">&#34;__all__&#34;</span>
</span></span><span class="line"><span class="cl">                <span class="n">exclude</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;title&#39;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">                <span class="n">labels</span> <span class="o">=</span> <span class="p">{</span> <span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;Writer&#39;</span><span class="p">,</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">                <span class="n">help_texts</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="s1">&#39;some useful help text.&#39;</span><span class="p">,}</span>
</span></span><span class="line"><span class="cl">                <span class="n">error_messages</span><span class="o">=</span><span class="p">{</span> <span class="s1">&#39;name&#39;</span><span class="p">:{</span><span class="s1">&#39;max_length&#39;</span><span class="p">:</span><span class="s2">&#34;this writer name is too long&#34;</span><span class="p">}</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">                <span class="n">widgets</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;name&#39;</span><span class="p">:</span><span class="n">Textarea</span><span class="p">(</span><span class="n">attrs</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;cols&#39;</span><span class="p">:</span><span class="mi">80</span><span class="p">,</span><span class="s1">&#39;rows&#39;</span><span class="p">:</span><span class="mi">20</span><span class="p">})}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="k">class</span> <span class="nc">UserInfoAdmin</span><span class="p">(</span><span class="n">admin</span><span class="o">.</span><span class="n">ModelAdmin</span><span class="p">):</span>
</span></span><span class="line"><span class="cl">            <span class="n">form</span> <span class="o">=</span> <span class="n">UserInfoForm</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">        <span class="n">admin</span><span class="o">.</span><span class="n">site</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">UserInfo</span><span class="p">,</span> <span class="n">UserInfoAdmin</span><span class="p">)</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h3 id="django模型类中字段的参数">django模型类中字段的参数</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span><span class="lnt">24
</span><span class="lnt">25
</span><span class="lnt">26
</span><span class="lnt">27
</span><span class="lnt">28
</span><span class="lnt">29
</span><span class="lnt">30
</span><span class="lnt">31
</span><span class="lnt">32
</span><span class="lnt">33
</span><span class="lnt">34
</span><span class="lnt">35
</span><span class="lnt">36
</span><span class="lnt">37
</span><span class="lnt">38
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl">	<span class="n">null</span>                <span class="n">数据库中字段是否可以为空</span>
</span></span><span class="line"><span class="cl">    <span class="n">db_column</span>           <span class="n">数据库中字段的列名</span>
</span></span><span class="line"><span class="cl">    <span class="n">default</span>             <span class="n">数据库中字段的默认值</span>
</span></span><span class="line"><span class="cl">    <span class="n">primary_key</span>         <span class="n">数据库中字段是否为主键</span>
</span></span><span class="line"><span class="cl">    <span class="n">db_index</span>            <span class="n">数据库中字段是否可以建立索引</span>
</span></span><span class="line"><span class="cl">    <span class="n">unique</span>              <span class="n">数据库中字段是否可以建立唯一索引</span>
</span></span><span class="line"><span class="cl">    <span class="n">unique_for_date</span>     <span class="n">数据库中字段</span><span class="err">【</span><span class="n">日期</span><span class="err">】</span><span class="n">部分是否可以建立唯一索引</span>
</span></span><span class="line"><span class="cl">    <span class="n">unique_for_month</span>    <span class="n">数据库中字段</span><span class="err">【</span><span class="n">月</span><span class="err">】</span><span class="n">部分是否可以建立唯一索引</span>
</span></span><span class="line"><span class="cl">    <span class="n">unique_for_year</span>     <span class="n">数据库中字段</span><span class="err">【</span><span class="n">年</span><span class="err">】</span><span class="n">部分是否可以建立唯一索引</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">verbose_name</span>        <span class="n">Admin中显示的字段名称</span>
</span></span><span class="line"><span class="cl">    <span class="n">blank</span>               <span class="n">Admin中是否允许用户输入为空</span>
</span></span><span class="line"><span class="cl">    <span class="n">editable</span>            <span class="n">Admin中是否可以编辑</span>
</span></span><span class="line"><span class="cl">    <span class="n">help_text</span>           <span class="n">Admin中该字段的提示信息</span>
</span></span><span class="line"><span class="cl">    <span class="n">choices</span>             <span class="n">Admin中显示选择框的内容</span><span class="err">，</span><span class="n">用不变动的数据放在内存中从而避免跨表操作</span>
</span></span><span class="line"><span class="cl">                        <span class="n">如</span><span class="err">：</span><span class="n">gf</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">(</span><span class="n">choices</span><span class="o">=</span><span class="p">[(</span><span class="mi">0</span><span class="p">,</span> <span class="s1">&#39;何穗&#39;</span><span class="p">),(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;大表姐&#39;</span><span class="p">),],</span><span class="n">default</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">error_messages</span>      <span class="n">自定义错误信息</span><span class="err">（</span><span class="n">字典类型</span><span class="err">），</span><span class="n">从而定制想要显示的错误信息</span><span class="err">；</span>
</span></span><span class="line"><span class="cl">                        <span class="n">字典健</span><span class="err">：</span><span class="n">null</span><span class="p">,</span> <span class="n">blank</span><span class="p">,</span> <span class="n">invalid</span><span class="p">,</span> <span class="n">invalid_choice</span><span class="p">,</span> <span class="n">unique</span><span class="p">,</span> <span class="ow">and</span> <span class="n">unique_for_date</span>
</span></span><span class="line"><span class="cl">                        <span class="n">如</span><span class="err">：</span><span class="p">{</span><span class="s1">&#39;null&#39;</span><span class="p">:</span> <span class="s2">&#34;不能为空.&#34;</span><span class="p">,</span> <span class="s1">&#39;invalid&#39;</span><span class="p">:</span> <span class="s1">&#39;格式错误&#39;</span><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">validators</span>          <span class="n">自定义错误验证</span><span class="err">（</span><span class="n">列表类型</span><span class="err">），</span><span class="n">从而定制想要的验证规则</span>
</span></span><span class="line"><span class="cl">                        <span class="kn">from</span> <span class="nn">django.core.validators</span> <span class="kn">import</span> <span class="n">RegexValidator</span>
</span></span><span class="line"><span class="cl">                        <span class="kn">from</span> <span class="nn">django.core.validators</span> <span class="kn">import</span> <span class="n">EmailValidator</span><span class="p">,</span><span class="n">URLValidator</span><span class="p">,</span><span class="n">DecimalValidator</span><span class="p">,</span>\
</span></span><span class="line"><span class="cl">                        <span class="n">MaxLengthValidator</span><span class="p">,</span><span class="n">MinLengthValidator</span><span class="p">,</span><span class="n">MaxValueValidator</span><span class="p">,</span><span class="n">MinValueValidator</span>
</span></span><span class="line"><span class="cl">                        <span class="n">如</span><span class="err">：</span>
</span></span><span class="line"><span class="cl">                            <span class="n">test</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span>
</span></span><span class="line"><span class="cl">                                <span class="n">max_length</span><span class="o">=</span><span class="mi">32</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">                                <span class="n">error_messages</span><span class="o">=</span><span class="p">{</span>
</span></span><span class="line"><span class="cl">                                    <span class="s1">&#39;c1&#39;</span><span class="p">:</span> <span class="s1">&#39;优先错信息1&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">                                    <span class="s1">&#39;c2&#39;</span><span class="p">:</span> <span class="s1">&#39;优先错信息2&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">                                    <span class="s1">&#39;c3&#39;</span><span class="p">:</span> <span class="s1">&#39;优先错信息3&#39;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">                                <span class="p">},</span>
</span></span><span class="line"><span class="cl">                                <span class="n">validators</span><span class="o">=</span><span class="p">[</span>
</span></span><span class="line"><span class="cl">                                    <span class="n">RegexValidator</span><span class="p">(</span><span class="n">regex</span><span class="o">=</span><span class="s1">&#39;root_\d+&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s1">&#39;错误了&#39;</span><span class="p">,</span> <span class="n">code</span><span class="o">=</span><span class="s1">&#39;c1&#39;</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">                                    <span class="n">RegexValidator</span><span class="p">(</span><span class="n">regex</span><span class="o">=</span><span class="s1">&#39;root_112233\d+&#39;</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s1">&#39;又错误了&#39;</span><span class="p">,</span> <span class="n">code</span><span class="o">=</span><span class="s1">&#39;c2&#39;</span><span class="p">),</span>
</span></span><span class="line"><span class="cl">                                    <span class="n">EmailValidator</span><span class="p">(</span><span class="n">message</span><span class="o">=</span><span class="s1">&#39;又错误了&#39;</span><span class="p">,</span> <span class="n">code</span><span class="o">=</span><span class="s1">&#39;c3&#39;</span><span class="p">),</span> <span class="p">]</span>
</span></span><span class="line"><span class="cl">                            <span class="p">)</span>
</span></span></code></pre></td></tr></table>
</div>
</div><p>这是一个经典的权限访问控制系统：rbac（Role-Based Access Control）基于角色的权限访问控制。</p>
<h3 id="目录结构">目录结构</h3>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre tabindex="0" class="chroma"><code><span class="lnt"> 1
</span><span class="lnt"> 2
</span><span class="lnt"> 3
</span><span class="lnt"> 4
</span><span class="lnt"> 5
</span><span class="lnt"> 6
</span><span class="lnt"> 7
</span><span class="lnt"> 8
</span><span class="lnt"> 9
</span><span class="lnt">10
</span><span class="lnt">11
</span><span class="lnt">12
</span><span class="lnt">13
</span><span class="lnt">14
</span><span class="lnt">15
</span><span class="lnt">16
</span><span class="lnt">17
</span><span class="lnt">18
</span><span class="lnt">19
</span><span class="lnt">20
</span><span class="lnt">21
</span><span class="lnt">22
</span><span class="lnt">23
</span></code></pre></td>
<td class="lntd">
<pre tabindex="0" class="chroma"><code class="language-python" data-lang="python"><span class="line"><span class="cl"><span class="n">luffy_permission</span><span class="o">/</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="n">db</span><span class="o">.</span><span class="n">sqlite3</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="n">luffy_permission</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">settings</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">urls</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">└──</span> <span class="n">wsgi</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="n">manage</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="n">rbac</span>            <span class="c1"># 权限组件，便于以后应用到其他系统</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">admin</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">apps</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">models</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">├──</span> <span class="n">tests</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">│</span>   <span class="err">└──</span> <span class="n">views</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl"><span class="err">├──</span> <span class="n">templates</span>
</span></span><span class="line"><span class="cl"><span class="err">└──</span> <span class="n">web</span>            <span class="c1"># 客户管理业务</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="n">admin</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="n">apps</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="n">models</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl">    <span class="err">├──</span> <span class="n">tests</span><span class="o">.</span><span class="n">py</span>
</span></span><span class="line"><span class="cl">    <span class="err">└──</span> <span class="n">views</span><span class="o">.</span><span class="n">py</span>
</span></span></code></pre></td></tr></table>
</div>
</div><h2 id="stark组件增删改查组件">Stark组件(增删改查组件)</h2>
<p>stark组件，是一个帮助开发者快速实现数据库表的增删改查+的组件。</p>
<h2 id="crm业务用权限和增删改查组成crm业务">crm业务(用权限和增删改查组成crm业务)</h2>

</section>


    <footer class="article-footer">
    
    <section class="article-tags">
        
            <a href="/tags/%E4%BB%A3%E7%A0%81/">代码</a>
        
    </section>


    
    <section class="article-copyright">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copyright" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <path d="M14.5 9a3.5 4 0 1 0 0 6" />
</svg>



        <span>Licensed under CC BY-NC-SA 4.0</span>
    </section>
    </footer>


    
</article>

    

    

     
    
        
    

    <footer class="site-footer">
    <section class="copyright">
        &copy; 
        
            2020 - 
        
        2023 梅鲁梅鲁梅鲁梅~
    </section>
    
    <section class="powerby">
        Built with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> <br />
        Theme <b><a href="https://github.com/CaiJimmy/hugo-theme-stack" target="_blank" rel="noopener" data-version="3.13.0">Stack</a></b> designed by <a href="https://jimmycai.com" target="_blank" rel="noopener">Jimmy</a>
    </section>
</footer>


    
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    
    <div class="pswp__bg"></div>

    
    <div class="pswp__scroll-wrap">

        
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                
                
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"integrity="sha256-ePwmChbbvXbsO02lbM3HoHbSHTHFAeChekF1xKJdleo="crossorigin="anonymous"
                defer
                >
            </script><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"integrity="sha256-UKkzOn/w1mBxRmLLGrSeyB4e1xbrp4xylgAWb3M42pU="crossorigin="anonymous"
                defer
                >
            </script><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css"crossorigin="anonymous"
            ><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css"crossorigin="anonymous"
            >

            </main>
    <aside class="sidebar right-sidebar sticky">
        
            
                
    <section class="widget archives">
        <div class="widget-icon">
            <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-hash" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <line x1="5" y1="9" x2="19" y2="9" />
  <line x1="5" y1="15" x2="19" y2="15" />
  <line x1="11" y1="4" x2="7" y2="20" />
  <line x1="17" y1="4" x2="13" y2="20" />
</svg>



        </div>
        <h2 class="widget-title section-title">Table of contents</h2>
        
        <div class="widget--toc">
            <nav id="TableOfContents">
  <ol>
    <li><a href="#权限系统做成公共组件app">权限系统(做成公共组件app)</a>
      <ol>
        <li><a href="#权限表结构设计">权限表结构设计</a></li>
        <li><a href="#django中的model字段">django中的model字段</a></li>
        <li><a href="#django模型类中字段的参数">django模型类中字段的参数</a></li>
        <li><a href="#目录结构">目录结构</a></li>
      </ol>
    </li>
    <li><a href="#stark组件增删改查组件">Stark组件(增删改查组件)</a></li>
    <li><a href="#crm业务用权限和增删改查组成crm业务">crm业务(用权限和增删改查组成crm业务)</a></li>
  </ol>
</nav>
        </div>
    </section>

            
        
    </aside>


        </div>
        <script 
                src="https://cdn.jsdelivr.net/npm/node-vibrant@3.1.6/dist/vibrant.min.js"integrity="sha256-awcR2jno4kI5X0zL8ex0vi2z&#43;KMkF24hUW8WePSA9HM="crossorigin="anonymous"
                
                >
            </script><script type="text/javascript" src="/ts/main.js" defer></script>
<script>
    (function () {
        const customFont = document.createElement('link');
        customFont.href = "https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap";

        customFont.type = "text/css";
        customFont.rel = "stylesheet";

        document.head.appendChild(customFont);
    }());
</script>

    </body>
</html>
